package com.lishe.lishe.lishe.module.mall.adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.MyRecyclerView.RecyclerviewBaseAdapter;
import com.lishe.lishe.lishe.module.mall.bean.category.CategoryFirst;

import java.util.List;

/**
 * Created by yang on 2017/11/6.
 */

public class Classification1Adapter extends RecyclerviewBaseAdapter {
    private Context mContext;
    private List<CategoryFirst> mList;
    private int selectPosition=0;

    public Classification1Adapter(Context context, List<CategoryFirst> list){
        this.mContext=context;
        this.mList=list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolderMy(ViewGroup parent, int viewType) {

        View view= LayoutInflater.from(mContext).inflate(R.layout.item_classification1,null);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolderMy(RecyclerView.ViewHolder holder, int position) {
        ((MyViewHolder)holder).tv.setText(mList.get(position).getCate_name());
        if(position==selectPosition){
            ((MyViewHolder)holder).tv.setTextColor(mContext.getResources().getColor(R.color.color_FF4138));
            ((MyViewHolder)holder).tv.setBackgroundColor(mContext.getResources().getColor(R.color.content_bg));
        }else{
            ((MyViewHolder)holder).tv.setTextColor(mContext.getResources().getColor(R.color.color_333333));
            ((MyViewHolder)holder).tv.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }
    }

    @Override
    public int getItemCountMy() {
        return mList.size();
    }

    @Override
    public int getItemViewTypeMy(int position) {
        return 0;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{
        TextView tv;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv= itemView.findViewById(R.id.tv);
        }
    }

    public void setSelectPosition(int position){
        this.selectPosition=position;
        notifyDataSetChanged();
    }

}
